<?php

use think\migration\Migrator;
use think\migration\db\Column;
use Phinx\Db\Adapter\MysqlAdapter; //如创建MYSQL特有字段，需导入该命名空间

class CreateAdminsTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */


    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('admins');
        $table->addColumn('name', 'string', ['limit' => 20,'comment' => '用户名'])           
            ->addColumn('password', 'string', ['limit' => 64,'comment' => '密码'])
            ->addColumn('status', 'string', ['limit' => MysqlAdapter::INT_TINY,'default' => 1,'comment'=>'状态'])
            ->addColumn('role_id', 'string', ['limit' => MysqlAdapter::INT_TINY,'comment' => '角色id'])
            ->addColumn('email', 'string', ['limit' => 30,'null' => true,'default' => '','comment' => '邮箱'])
            ->addColumn('realname', 'string', ['limit' => 20,'null' => true,'default' => '','comment' => '真实姓名'])
            ->addColumn('cerprivs', 'text', ['limit' => 64,'null' => true,'comment' => '渠道号'])
            ->addColumn('last_login_ip', 'string', ['limit' => 16,'null' => true,'default' => '','comment' => '最后登录ip'])
            ->addColumn('last_login_time', 'datetime', ['null' => true,'comment' => '最后登录时间'])
            ->addColumn('created_at', 'datetime', ['null' => true,'comment' => '创建时间'])
            ->addColumn('updated_at', 'datetime', ['null' => true])
            ->addColumn('appids', 'text', ['null' => true,'comment' => '查看游戏'])
            ->addColumn('parent_id', 'integer', ['limit' => MysqlAdapter::INT_MEDIUM,'default' => 0,'comment' => '上级id'])
            ->addColumn('department_id', 'integer', ['limit' => MysqlAdapter::INT_MEDIUM,'default' => 0,'comment' => '部门id'])
            ->addColumn('userrank', 'integer', ['limit' => MysqlAdapter::INT_TINY,'default' => 0,'comment' => '0是普通成员1是主管2是组长'])
            ->addColumn('openid', 'string', ['limit' => 255,'null' => true,'default' => '','comment' => '用户openid'])
            ->addIndex(['name'], ['unique' => true])
            ->save();
    }
    /**
     * Migrate Down.
     */
    public function down()
    {
        if($this->hasTable('admins')){
            $this->dropTable('admins');
        }
    }
}
